package com.example.pandaso.engines.extend;

import java.util.ArrayList;
import java.util.List;

import com.example.pandaso.engines.BaseEngine;
import com.example.pandaso.pojo.SogSearchResult;
import com.example.pandaso.utils.HttpUtils;
import com.fasterxml.jackson.databind.ObjectMapper;

public class SougoEngine extends BaseEngine{

    @Override
    public List<String> getTips(String keyword) {
        List<String> suggestsList = new ArrayList<String>();
        String  json = HttpUtils.getEntity("https://sug.so.360.cn/suggest?encodein=utf-8&encodeout=utf-8&format=json&word="+keyword);
        try{
            ObjectMapper objectMapper = new ObjectMapper();
            SogSearchResult sogSearchResult = objectMapper.readValue(json, SogSearchResult.class);
            for(SogSearchResult.ResultItem r : sogSearchResult.getResult()){
                suggestsList.add(r.getWord());
            }

        }catch(Exception e){
            e.printStackTrace();
        }
        
        return suggestsList;
    }
    
}
